home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 39 / Amiga Format CD39 (1999-04-13)(Future Publishing)(GB)[!][issue 1999-05].iso / -seriously_amiga- / graphics / ripley / source / screen.c < prev    next >
C/C++ Source or Header  |  1999-03-02  |  11KB  |  517 lines

  1. /*********************************************************************
  2. ----------------------------------------------------------------------
  3.  
  4.     screen
  5.  
  6. ----------------------------------------------------------------------
  7. *********************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12.  
  13. #include <utility/tagitem.h>
  14. #include <workbench/startup.h>
  15. #include <workbench/workbench.h>
  16. #include <libraries/cybergraphics.h>
  17. #include <intuition/intuition.h>
  18.  
  19. #include <clib/macros.h>
  20.  
  21. #include <proto/asl.h>
  22. #include <proto/exec.h>
  23. #include <proto/intuition.h>
  24. #include <proto/graphics.h>
  25. #include <proto/utility.h>
  26. #include <proto/guigfx.h>
  27. #include <proto/cybergraphics.h>
  28. #include <proto/wb.h>
  29. #include <proto/dos.h>
  30. #include <proto/intuition.h>
  31. #include <proto/gadtools.h>
  32. #include <proto/diskfont.h>
  33.  
  34. #include "screen.h"
  35. #include "mplay.h"
  36. #include "commandline.h"
  37.  
  38.  
  39. static int getnumopt(int index)
  40. {
  41.     if (opts[index])
  42.     {
  43.         return (int) *((LONG *) opts[index]);
  44.     }
  45.     
  46.     return 0;
  47. }
  48.  
  49.  
  50.  
  51. /*--------------------------------------------------------------------
  52.  
  53.     GetScreenAspect(screen, *aspectx, *aspecty)
  54.  
  55. --------------------------------------------------------------------*/
  56.  
  57. void GetScreenAspect(struct Screen *screen, int *aspectx, int *aspecty)
  58. {
  59.     ULONG modeID;
  60.     *aspectx = 1;
  61.     *aspecty = 1;
  62.  
  63.     if ((modeID = GetVPModeID(&screen->ViewPort)) != INVALID_ID)
  64.     {
  65.         DisplayInfoHandle dih;
  66.  
  67.         if(dih = FindDisplayInfo(modeID))
  68.         {
  69.             struct DisplayInfo di;    
  70.  
  71.             if(GetDisplayInfoData(dih, (UBYTE*)&di, sizeof(struct DisplayInfo), DTAG_DISP, modeID))
  72.             {
  73.                 *aspectx = (int) di.Resolution.x;
  74.                 *aspecty = (int) di.Resolution.y;
  75.             }
  76.         }
  77.     }
  78. }
  79.  
  80. /*********************************************************************
  81. ----------------------------------------------------------------------
  82.  
  83.     void DeleteMVScreen(mvscreen)
  84.  
  85. ----------------------------------------------------------------------
  86. *********************************************************************/
  87.  
  88. void DeleteMVScreen(struct mvscreen *scr)
  89. {
  90.     if (scr)
  91.     {
  92.  
  93. //        if (scr->screenfont)
  94. //        {
  95. //            CloseFont(scr->screenfont);
  96. //        }
  97.  
  98. //        DeletePenShareMap(scr->psm);
  99.  
  100.         FreeVisualInfo(scr->visualinfo);
  101.  
  102.         if (scr->screen)
  103.         {
  104.             if (scr->screentype == CUSTOMSCREEN)
  105.             {
  106.                 while ( (PubScreenStatus(scr->screen, PSNF_PRIVATE) & 1) == 0)
  107.                 {
  108.                     Delay(10);
  109.                 }
  110.                 CloseScreen(scr->screen);
  111.             }
  112.             else
  113.             {            
  114.                 UnlockPubScreen(NULL, scr->screen);
  115.             }
  116.         }            
  117.         free(scr);
  118.     }
  119. }
  120.  
  121.  
  122.  
  123.  
  124. /*********************************************************************
  125. ----------------------------------------------------------------------
  126.  
  127.     GetVisibleSize(mvscreen, &width, &height)
  128.  
  129. ----------------------------------------------------------------------
  130. *********************************************************************/
  131.  
  132. void GetVisibleSize(struct mvscreen *scr, int *width, int *height)
  133. {
  134.     if (scr)
  135.     {
  136.         DisplayInfoHandle dih;
  137.         struct DimensionInfo di;    
  138.  
  139.         *width = scr->screen->Width;
  140.         *height = scr->screen->Height;
  141.         
  142.         if(dih = FindDisplayInfo(scr->modeID))
  143.         {
  144.             if(GetDisplayInfoData(dih, (UBYTE*) &di, sizeof(di), DTAG_DIMS, scr->modeID))
  145.             {
  146.                 *width = di.TxtOScan.MaxX - di.TxtOScan.MinX + 1;
  147.                 *height = di.TxtOScan.MaxY - di.TxtOScan.MinY + 1;
  148.             }
  149.         }
  150.  
  151.     }
  152. }
  153.  
  154.  
  155. /*********************************************************************
  156. ----------------------------------------------------------------------
  157.  
  158.     struct mvscreen *CreateMVScreen(mvs)
  159.  
  160. ----------------------------------------------------------------------
  161. *********************************************************************/
  162.  
  163. struct mvscreen *CreateMVScreen(void)
  164. {
  165. #define inserttag(x,t,d) {(x)->ti_Tag=(t);((x)++)->ti_Data=(ULONG)(d);}
  166.  
  167.     struct mvscreen *scr;
  168.  
  169.     if (scr = malloc(sizeof(struct mvscreen)))
  170.     {
  171.         BOOL success = FALSE;
  172.  
  173.         memset(scr, 0, sizeof(struct mvscreen));
  174.  
  175.         InitSemaphore(&scr->semaphore);
  176.  
  177.         if (opts[OPT_CUSTOMSCREEN])
  178. //        if (mvs->scropenmode == SCROPENMODE_CUSTOM)
  179.         {
  180.             ULONG id = INVALID_ID;
  181.             UWORD width, height, depth;
  182.             struct Screen *defscreen = NULL;
  183.             struct ViewPort *vp = NULL;
  184.         
  185.             width = MINSCREENWIDTH;
  186.             height = MINSCREENHEIGHT;
  187.         //    depth = mvs->depth ? mvs->depth : MINSCREENDEPTH;
  188.  
  189.             depth = getnumopt(OPT_DEPTH);
  190.             if (!depth) depth = 1;
  191.  
  192.         //    if (mvs->modeID == INVALID_ID)
  193.         //    {
  194.                 if (defscreen = LockPubScreen(NULL))
  195.                 {
  196.                     ULONG modeID;
  197.                     vp = &defscreen->ViewPort;
  198.     
  199.                     width = defscreen->Width;
  200.                     height = defscreen->Height;
  201.     
  202.                     if ((modeID = GetVPModeID(vp)) != INVALID_ID)
  203.                     {
  204.                         DisplayInfoHandle dih;
  205.                 
  206.                         if(dih = FindDisplayInfo(modeID))
  207.                         {
  208.                             struct DimensionInfo di;    
  209.                 
  210.                             if(GetDisplayInfoData(dih, (UBYTE*) &di, sizeof(di), DTAG_DIMS, modeID))
  211.                             {
  212.                                 width = di.StdOScan.MaxX - di.StdOScan.MinX + 1;
  213.                                 height = di.StdOScan.MaxY - di.StdOScan.MinY + 1;
  214.                                 if (!getnumopt(OPT_DEPTH))
  215.                                 {
  216.                                     depth = di.MaxDepth;
  217.                                 }
  218.                             }
  219.                         }
  220.                     }
  221.                 }
  222.         //    }
  223. #if 0
  224.             else
  225.             {
  226.                 DisplayInfoHandle dih;
  227.  
  228.                 id = mvs->modeID;
  229.                 
  230.                 if(dih = FindDisplayInfo(id))
  231.                 {
  232.                     struct DimensionInfo di;    
  233.                 
  234.                     if(GetDisplayInfoData(dih, (UBYTE*) &di, sizeof(di), DTAG_DIMS, id))
  235.                     {
  236.                         width = di.StdOScan.MaxX - di.StdOScan.MinX + 1;
  237.                         height = di.StdOScan.MaxY - di.StdOScan.MinY + 1;
  238.                         if (!mvs->depth)
  239.                         {
  240.                             depth = di.MaxDepth;
  241.                         }
  242.                     }
  243.                 }
  244.             }
  245. #endif
  246.  
  247.         //    if (mvs->scrwidth > 0)
  248.             if (getnumopt(OPT_SCRWIDTH) > 0)
  249.             {
  250.             //    width = mvs->scrwidth;
  251.                 width = getnumopt(OPT_SCRWIDTH);
  252.             }
  253.             
  254.         //    if (mvs->scrheight > 0)
  255.             if (getnumopt(OPT_SCRHEIGHT) > 0)
  256.             {
  257.             //    height = mvs->scrheight;
  258.                 height = getnumopt(OPT_SCRHEIGHT); 
  259.             }
  260.  
  261.  
  262.         //    if (mvs->modeID == INVALID_ID)
  263.         //    {
  264.             //    if (CyberGfxBase && !mvs->hamscreen)
  265.                 if (CyberGfxBase && !opts[OPT_HAM])
  266.                 {
  267.                     struct TagItem *taglist;
  268.                     if (taglist = AllocateTagItems(10))
  269.                     {
  270.                         struct TagItem *tp = taglist;
  271.                         int d;
  272.                     
  273.                         inserttag(tp, CYBRBIDTG_NominalWidth, width);
  274.                         inserttag(tp, CYBRBIDTG_NominalHeight, height);
  275.     
  276.                         d = getnumopt(OPT_DEPTH);
  277.                         if (d)
  278.                         {
  279.                         
  280.                             inserttag(tp, CYBRBIDTG_Depth, RNG(MINSCREENDEPTH, d, 32));
  281.                         }
  282.                         inserttag(tp, TAG_DONE, 0);
  283.                     
  284.                         id = BestCModeIDTagList(taglist);
  285.             
  286.                         FreeTagItems(taglist);
  287.                     }
  288.                 }
  289.  
  290.                 if (id == INVALID_ID)
  291.                 {
  292.                     struct TagItem *taglist;
  293.                     if (taglist = AllocateTagItems(10))
  294.                     {
  295.                         struct TagItem *tp = taglist;
  296.             
  297.                         inserttag(tp, BIDTAG_NominalWidth, width);
  298.                         inserttag(tp, BIDTAG_NominalHeight, height);
  299.     
  300.                         if (opts[OPT_HAM])
  301.                         {
  302.                             inserttag(tp, BIDTAG_DIPFMustHave, DIPF_IS_HAM);
  303.                             depth = MIN(depth, 8);
  304.                         }
  305.                         else
  306.                         {
  307.                             inserttag(tp, BIDTAG_ViewPort, vp);
  308.                             if (getnumopt(OPT_DEPTH))
  309.                             {
  310.                                 inserttag(tp, BIDTAG_Depth, depth);
  311.                             }
  312.                         }
  313.     
  314.                         inserttag(tp, TAG_DONE, 0);
  315.             
  316.                         id = BestModeIDA(taglist);
  317.                         FreeTagItems(taglist);
  318.                     }
  319.                 }
  320.         //    }
  321.  
  322.  
  323.             if (scr->screen = LockPubScreen(PROGNAME))
  324.             {
  325.                 scr->screentype = PUBLICSCREEN;
  326.                 success = TRUE;
  327.                 scr->modeID = GetVPModeID(&scr->screen->ViewPort);
  328.             }
  329.             else
  330.             {
  331.                 if (id != INVALID_ID)
  332.                 {
  333.                     UWORD empty = 0xffff;
  334.                     
  335.                     if (scr->screen = OpenScreenTags(NULL,
  336.                         SA_Width, width,
  337.                         SA_Height, height,
  338.                         SA_Depth, depth,
  339.                         SA_DisplayID, id, 
  340.                         SA_Type, PUBLICSCREEN,
  341.                         SA_AutoScroll, TRUE,
  342.                         SA_Title, PROGNAME,
  343.                         SA_PubName, PROGNAME,
  344.                         SA_ShowTitle, FALSE,
  345.                         SA_LikeWorkbench, TRUE,
  346.                         SA_FullPalette, TRUE,
  347.                         SA_SharePens, TRUE,
  348.                         SA_Pens, &empty,
  349.                         TAG_DONE))
  350.                     {
  351.                         PubScreenStatus(scr->screen, 0);
  352.                         scr->screentype = CUSTOMSCREEN;
  353.  
  354. /*****                        
  355.                         ///////////////////////777
  356.                         
  357.                         {
  358.                             APTR handle;
  359.                             ULONG *adr;
  360.                             
  361.                             handle = LockBitMapTags(scr->screen->RastPort.BitMap,
  362.                                 LBMI_BASEADDRESS, &adr, TAG_DONE);
  363.                                                     
  364.                             UnLockBitMap(handle);        
  365.  
  366.                             printf("%x\n", adr);
  367.     
  368.                         }                    
  369. *****/                        
  370.                         ////////////////////////
  371.                         
  372.                         
  373.  
  374.                         success = TRUE;
  375.                     }
  376.                 }
  377.             }
  378.  
  379.             if (defscreen)
  380.             {
  381.                 UnlockPubScreen(NULL, defscreen);
  382.             }
  383.         }
  384.  
  385.         //else
  386.         
  387.         if (!success)
  388.         {
  389.  
  390.             if (!success)
  391.             {
  392.                 if (opts[OPT_PUBSCREEN])
  393.             //    if (mvs->scropenmode == SCROPENMODE_PUBLIC)
  394.                 {
  395.                     if (scr->screen = LockPubScreen((char *) opts[OPT_PUBSCREEN]))
  396.                     {
  397.                         ScreenToFront(scr->screen);
  398.                         success = TRUE;
  399.                     }
  400.                 }
  401.             }
  402.             
  403.             if (!success)
  404.             {
  405.                 success = !!(scr->screen = LockPubScreen(NULL));        
  406.             }
  407.  
  408.             if (success)
  409.             {
  410.                 scr->screentype = PUBLICSCREEN;
  411.                 scr->modeID = GetVPModeID(&scr->screen->ViewPort);
  412.             }
  413.         }
  414.  
  415.         if (success)
  416.         {
  417.             success = FALSE;
  418.  
  419.             if (scr->visualinfo = GetVisualInfo(scr->screen, TAG_DONE))
  420.             {
  421.             //    if (scr->psm = CreatePenShareMap(GGFX_HSType, HISTOGRAMTYPE, TAG_DONE))
  422.             //    {
  423.                 //    if (mvs->screenaspectx > 0 && mvs->screenaspecty > 0)
  424.                 //    {
  425.                 //        scr->aspectx = mvs->screenaspectx;
  426.                 //        scr->aspecty = mvs->screenaspecty;
  427.                 //    }
  428.                 //    else
  429.                 //    {
  430.                         GetScreenAspect(scr->screen, &scr->aspectx, &scr->aspecty);
  431.                 //    }
  432.                     success = TRUE;
  433.             //    }
  434.             }
  435.         }
  436.  
  437.         if (success)
  438.         {
  439.             scr->modeID = GetVPModeID(&scr->screen->ViewPort);
  440.             scr->ham = FALSE;
  441.  
  442.             if (scr->modeID != INVALID_ID)
  443.             {
  444.                 DisplayInfoHandle dih;
  445.                 if(dih = FindDisplayInfo(scr->modeID))
  446.                 {
  447.                     struct DisplayInfo di;    
  448.             
  449.                     if(GetDisplayInfoData(dih, (UBYTE*)&di, sizeof(struct DisplayInfo), DTAG_DISP, scr->modeID))
  450.                     {
  451.                         scr->ham = !!(di.PropertyFlags & DIPF_IS_HAM);
  452.                     }
  453.                 }
  454.             }
  455.  
  456. #if 0
  457.  
  458.             struct TextAttr fattr;
  459.             fattr.ta_Name = (STRPTR) scr->screen->RastPort.Font->tf_Message.mn_Node.ln_Name;
  460.             fattr.ta_YSize = scr->screen->RastPort.Font->tf_YSize;
  461.             fattr.ta_Style = FS_NORMAL;
  462.             fattr.ta_Flags = FPF_DESIGNED;
  463.  
  464.             if (mvs->fontspec)
  465.             {
  466.                 char fontname[102];
  467.                 int fontysize;
  468.                 char fontstring[110];
  469.             
  470.                 switch (sscanf(mvs->fontspec, "%lu,%100s", &fontysize, fontname))
  471.                 {
  472.                     case 2:
  473.                         sprintf(fontstring, "%s.font", fontname);
  474.                         fattr.ta_Name = fontstring;
  475.                         fattr.ta_YSize = fontysize;
  476.                         break;
  477.                     case 1:
  478.                         fattr.ta_YSize = fontysize;
  479.                         break;
  480.                     default:
  481.                         break;
  482.                 }
  483.  
  484.                 if (DiskFontBase)
  485.                 {
  486.                     scr->screenfont = OpenDiskFont(&fattr);
  487.                 }
  488.                 else
  489.                 {
  490.                     scr->screenfont = OpenFont(&fattr);
  491.                 }
  492.             }
  493.  
  494.             if (!scr->screenfont)
  495.             {
  496.                 fattr.ta_Name = (STRPTR) scr->screen->RastPort.Font->tf_Message.mn_Node.ln_Name;
  497.                 fattr.ta_YSize = scr->screen->RastPort.Font->tf_YSize;
  498.                 fattr.ta_Style = FS_NORMAL;
  499.                 fattr.ta_Flags = 0;
  500.                 scr->screenfont = OpenFont(&fattr);    
  501.             }
  502.  
  503. #endif
  504.  
  505.         }
  506.         else
  507.         {
  508.             DeleteMVScreen(scr);
  509.             scr = NULL;
  510.         }
  511.     }
  512.  
  513.     return scr;
  514.  
  515. #undef inserttag
  516. }
  517.